package com.anzia.storeback.dao;

import com.anzia.storeback.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ShoppingCartDao {

    // 更新用户购物车
    @Update("update shoppingcart set num=#{num} where user_id=#{user_id} and product_id=#{product_id}")
    void updateShoppingCart(int user_id, int product_id, int num);

    // 根据用户id和商品id添加到购物车
    @Insert("insert into shoppingcart(user_id, product_id, num) values(#{user_id}, #{product_id}, 1)")
    void addShoppingCart(int user_id, int product_id);

    // 根据用户id和商品id查询购物车商品信息
    @Select("select * from shoppingcart where user_id=#{user_id} and product_id=#{product_id}")
    ShoppingCart findShoppingCart(int user_id, int product_id);

    // 根据用户id查询购物车中所有商品信息
    @Select("select * from shoppingcart where user_id=#{user_id}")
    List<ShoppingCart> getShoppingCart(int user_id);

    // 根据用户id和商品id删除购物车中商品
    @Delete("delete from shoppingcart where user_id=#{user_id} and product_id=#{product_id}")
    void deleteShoppingCart(int user_id, int product_id);

}
